<template>
  <div id="app">
    <h1>{{ title }}</h1>
    <input type="text" v-model="item"/>
    <button @click="add(item)">添加</button>
    <ul>
      <li v-for="(todo,index) in todos"
          :class="{'checked':todo.done}">
        <label>{{index +1}}.{{todo.value}}</label>
        <time>{{todo.created|date}}</time>
      </li>
    </ul>
  </div>
</template>
<script>
  export default {
    name :'app',
    methods:{
      add:function(x) {
        this.todos.push({value: this.item, done: false,created: new Date().getTime()});
      }
    },

    data () {
      return {
        item:'',
        title: "vue-todos",
        todos: [{
          value: "阅读", done: false,
          created: Date.now()
        },
          {
            value: "补充", done: true,
            created: Date.now() + 300000
          },
          {
            value: "写心得", done: false,
            created: Date.now() - 300000
          }]
      }
    }
    , filters: {
      date(val)
      {
        return new Date(val).getHours() + ";" + new Date(val).getMinutes() + ":" + new Date(val).getSeconds();
      }
    }
  }
</script>
<style>
  .done{
    text-decoration:line-through ;
  }
</style>
